
//
//  GYVisitorView.swift
//  Weibo
//
//  Created by vane on 16/8/9.
//  Copyright © 2016年 apple. All rights reserved.
//

import UIKit
import SnapKit
class GYVisitorView: UIView {
    
    var closure:(()->())?

    override init(frame: CGRect) {
        
        super.init(frame: frame)
        
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private lazy var circleImageView:UIImageView = UIImageView(imgName: "visitordiscover_feed_image_smallicon")
    
    private lazy var houseImageView:UIImageView = UIImageView(imgName: "visitordiscover_feed_image_house")
    
    private lazy var maskImageView:UIImageView = UIImageView(imgName: "visitordiscover_feed_mask_smallicon")
    
    private lazy var messageLabel:UILabel = {
       
        let view = UILabel()
        
        view.text = "关注一些人，回这里看看有什么惊喜关注一些人，回这里看看有什么惊喜"
        view.textAlignment = NSTextAlignment.Center
        view.font = UIFont.systemFontOfSize(15)
        view.numberOfLines = 0
        view.textColor = AppThemeColor
        view.preferredMaxLayoutWidth = 240
    
        return view
    }()
    
    private lazy var registerBtn:UIButton = {
       
        let view = UIButton()
        
        view.setTitle("注册", forState: UIControlState.Normal)
        view.setBackgroundImage(UIImage(named: "common_button_white_disable"), forState: UIControlState.Normal)
        view.setTitleColor(AppThemeColor, forState: UIControlState.Normal)
        view.titleLabel?.font = UIFont.systemFontOfSize(15)
        view.addTarget(self, action: "buttonClick", forControlEvents: UIControlEvents.TouchUpInside)
        
        return view
    }()
    
    private lazy var loginBtn:UIButton = {
        
        let view = UIButton()
        
        view.setTitle("登录", forState: UIControlState.Normal)
        view.setBackgroundImage(UIImage(named: "common_button_white_disable"), forState: UIControlState.Normal)
        view.setTitleColor(AppThemeColor, forState: UIControlState.Normal)
        view.titleLabel?.font = UIFont.systemFontOfSize(15)
        view.addTarget(self, action: "buttonClick", forControlEvents: UIControlEvents.TouchUpInside)
        
        return view
    }()
    
    @objc private func buttonClick(){
        
        closure?()
//        print("点击")
        
    }
   
   private func setupUI(){
        
        backgroundColor = RGB(237, green:237, blue: 237)
        
        addSubview(circleImageView)
        addSubview(houseImageView)
        addSubview(maskImageView)
        addSubview(messageLabel)
        addSubview(registerBtn)
        addSubview(loginBtn)

        circleImageView.snp_makeConstraints { (make) -> Void in
            
            make.center.equalTo(self)
        }
        
        houseImageView.snp_makeConstraints { (make) -> Void in
            
            make.center.equalTo(self)
        }
        
        maskImageView.snp_makeConstraints { (make) -> Void in
            
            make.center.equalTo(self)
        }
        
        messageLabel.snp_makeConstraints { (make) -> Void in
            
            make.top.equalTo(maskImageView.snp_bottom).offset(16)
            make.centerX.equalTo(self)
           
        }
        registerBtn.snp_makeConstraints { (make) -> Void in
            
            make.leading.equalTo(messageLabel)
            make.top.equalTo(messageLabel.snp_bottom).offset(16)
            make.size.equalTo(CGSize(width: 100, height: 36))
        }
        
        loginBtn.snp_makeConstraints { (make) -> Void in
            
            make.size.top.equalTo(registerBtn)
            make.trailing.equalTo(messageLabel)
        }
        
    }
    func setupVisitorViewInfo(imgName: String?, title: String?){

        if let img = imgName, let tit = title {
        
            houseImageView.image = UIImage(named: img)
            
            messageLabel.text = tit

            circleImageView.hidden = true
        }else {

            setupAnim()
        }
    }
    func setupAnim(){
        let anim = CABasicAnimation(keyPath: "transform.rotation")
        
        anim.toValue = M_PI * 2
       
        anim.duration = 10
       
        anim.repeatCount = MAXFLOAT
        // 如果用户切换子控制器或者退到后台 默认动画移除
        anim.removedOnCompletion = false

        circleImageView.layer.addAnimation(anim, forKey: nil)
    }


}
